﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

@using LeSoft.Application.Code;
<script src="~/Content/adminDefault/js/default.js"></script>
<script>
    var keyWord = request('keyWord'), _Icode = "", _Iname = "", _type = 2, _organizeid = "@OperatorProvider.Provider.Current().CompanyId";
    $(function () {
        InitialPage();
        GetTree();
        GetDynamicCols();
    });

    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 165.5);
                $("#itemTree1").setTreeHeight($(window).height() - 624.5);
                $("#itemTree2").setTreeHeight($(window).height() - 381.5);
            }, 200);
            e.stopPropagation();
        });
        //组织机构
        $("#OrganizeId").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            height: "250px",
            description: "==请选择==",
            click: function (item) {
                _organizeid = item.id;
                $('#btn_Search').trigger("click");
            }
        });
        $('#OrganizeId').ComboBoxTreeSetValue(_organizeid);

        //点击看板
        $("#time_see a.btn-default").click(function () {
            $("#time_see a.btn-default").removeClass("active");
            $(this).addClass("active");
            _type = $(this).attr("data-value");
            GetDynamicCols();
        });
        //查询事件
        $("#btn_Search").click(function () {
            GetDynamicCols();
        });
        //查询回车
        $('#keyword').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                $('#btn_Search').trigger("click");
            }
        });
    }

    function GetTree() {
        var item = {
            height: $(window).height() - 52,
            url: "../../PropertyManage/CS_PollingResult/GetItemTreeJson?keyWord=" + keyWord,
            onnodeclick: function (item) {
                _Icode = item.id;
                _Iname = item.text;
                $('#btn_Search').trigger("click");
            }
        };
        //初始化
        $("#itemTree").treeview(item);
    }


    function GetDynamicCols() {
        $('#gridTable').GridUnload();
        var queryJson = $("#queryCondition").GetWebControls();
        queryJson["StartTime"] = queryJson["StartTime"] + " 00:00:00";
        queryJson["EndTime"] = queryJson["EndTime"] + " 23:59:59";
        queryJson["keyWord"] = keyWord;
        queryJson["Category"] = _type;
        queryJson["ItemId"] = _Icode;
        queryJson["OrganizeId"] = _organizeid;
        $.ajax({
            async: false,
            dataType: "json",
            data: { queryJson: JSON.stringify(queryJson) },
            url: "../../PropertyManage/CS_PollingResult/GetResultListJson",
            success: function (data) {
                creategrid(data);
            }
        });
    }


    //加载表格
    function creategrid(data) {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            datatype: 'local',
            height: $(window).height() - 175.5,
            autowidth: true,
            colModel: data.ColMs,
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortname: 'Name',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            unwritten: false,
            gridview: true,
            loadtext: "正在加载数据......",
            jsonReader: {
                root: data.Coldata.rows,
                page: data.Coldata.page,
                total: data.Coldata.total,
                records: data.Coldata.records,
                repeatitems: false
            },
            onSelectRow: function (status) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            },
            ondblClickRow: function (rowid, iRow, iCol, e) {

                if (iCol < 4 || data.ColMs.length == iCol) return;
                var obj = $("#" + this.id).getRowData(rowid);
                var StartTime = $("#StartTime").val() + " 00:00:00";
                var option = "?TypeId=" + obj.Type + "&ItemId=" + _Icode + "&ObjectId=" + obj.Id + "&Category=" + _type + "&StartTime=" + StartTime + "&DateAdd=" + (iCol - 4);
                top.tablist.newTab({ id: obj.id, title: '巡检明细【' + obj.Name + '】', closed: true, icon: "fa fa fa-eye", url: top.contentPath + '/PropertyManage/CS_PollingResult/Detail' + option });
            }
        });
        $gridTable.setGridParam({ data: data.Coldata.rows, localReader: $gridTable.jsonReader }).trigger('reloadGrid');

    }
</script>



<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">

    <div class="ui-layout-west">
        <div class="west-Panel">
            <div class="panel-Title">巡检项目目录</div>
            <div id="itemTree"></div>
        </div>

    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="panel-Title">巡检信息</div>
            <div class="titlePanel">
                <div class="title-search">
                    <table id="queryCondition">
                        <tr style="padding-left: 10px;">
                            <td>所属机构：</td>
                            <td style="width:200px;"><div id="OrganizeId" type="selectTree" class="ui-select"></div></td>
                            <td style="padding-left: 10px;">
                                <input id="StartTime" readonly type="text" value="@DateTime.Now.AddDays(-DateTime.Now.DayOfYear + 1).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker({})">
                            </td>
                            <td style="text-align: center; padding-left: 5px;">至</td>
                            <td style="padding-left: 5px;"><input id="EndTime" readonly type="text" value="@DateTime.Now.AddMonths(12 - DateTime.Now.Month + 1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker({})"></td>
                            <td style="padding-left: 10px;">
                                <div id="time_see" class="btn-group">
                                    <a class="btn btn-default" data-value="1">日看板</a>
                                    <a class="btn btn-default active" data-value="2">月看板</a>
                                    <a class="btn btn-default " data-value="3">年看板</a>
                                </div>
                            </td>
                            <td style="padding-left: 10px;">
                                <a id="btn_Search" class="btn btn-primary">&nbsp;查&nbsp;&nbsp;询</a>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <script>$('.toolbar').authorizeButton()</script>
                    </div>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
</div>
